FROM ruby:2.4.3-stretch

# 使用国内软件源
RUN echo "deb http://mirrors.aliyun.com/debian/ stretch main\n \
 deb http://mirrors.aliyun.com/debian/ stretch-updates main" > /etc/apt/sources.list

# 升级gem和bundle，并配置源
ENV RUBYGEMS_VERSION 2.7.6
ENV BUNDLER_VERSION 1.16.1
ENV LANG C.UTF-8

RUN apt-get update
RUN gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ \
	&& gem install bundler --version "$BUNDLER_VERSION" --force \
	&& gem update --system "$RUBYGEMS_VERSION" \
	&& bundle config mirror.https://rubygems.org https://gems.ruby-china.org

## POSTGRESQL 9.6 BEGIN
ENV PG_VERSION 9.6
ENV	PG_HOME /var/lib/postgresql
ENV	PG_DATADIR ${PG_HOME}/${PG_VERSION}/main

RUN apt-get install -y wget gnupg dirmngr
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' > 'etc/apt/sources.list.d/pgdg.list'; \
	wget --quiet -P /tmp https://www.postgresql.org/media/keys/ACCC4CF8.asc ;\
	apt-key add < /tmp/ACCC4CF8.asc >/dev/null

RUN apt-get update; \
	apt-get install -y postgresql-${PG_VERSION} postgresql-client-${PG_VERSION} postgresql-contrib-${PG_VERSION}

# 删除数据文件，初始化脚本中重新创建
RUN rm -rf "$PG_DATADIR"

## POSTGRESQL 9.6 END
RUN apt-get install -y redis-server; \
	apt-get install -y imagemagick; \
	apt-get install -y nginx; \
	apt-get install -y git; \
  apt-get install -y openssh-server;
# 安装vim
RUN apt-get install -y vim;

RUN rm -rf /var/lib/apt/lists/*
# 删除nginx默认站点
RUN rm /etc/nginx/conf.d/default
COPY ./templates/nginx/nginx.conf /etc/nginx/
COPY ./templates/nginx/rails.conf /etc/nginx/conf.d/

# 拷贝启动服务和初始化脚本
RUN mkdir /data
RUN mkdir /scripts
COPY ./templates/scripts/* /scripts/
RUN chmod a+x /scripts/*.sh

# 拷贝mina配置文件 - pdca
# RUN mkdir -p /mina/pdca/config
# COPY ./templates/pdca/mina/* /mina/pdca/
# RUN mv /mina/pdca/deploy.rb /mina/pdca/config/deploy.rb
# RUN cd /mina/pdca/ && bundle

# # 拷贝宿主机的ssh
COPY ./templates/ssh/* /root/.ssh/
RUN chmod -R 700 /root/.ssh/


CMD ["/scripts/docker_entrypoint.sh"]
